var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var import_electron = require("electron");
var import_path = __toESM(require("path"));
var import_url = require("url");
var import_grpcClient = __toESM(require("./grpcClient.js"));
const import_meta = {};
const __filename = (0, import_url.fileURLToPath)(import_meta.url);
const __dirname = import_path.default.dirname(__filename);
const isDevelopment = process.env.NODE_ENV !== "production";
const createVST3Parameter = (labelName, parameterId, processorId) => ({
  labelName,
  parameterId,
  processorId
});
const PluginType = {
  DUMMY: 0,
  INTERNAL: 1,
  VST2X: 2,
  VST3X: 3,
  LV2: 4
};
const AmplifierNo = {
  Eddie51Amplifier: 1,
  DizzlVHAmplifier: 2,
  SoloistAmplifier: 3
};
const amplifierConfigs = {
  SoloistAmplifier: {
    name: "Soloist Amplifier",
    uid: "com.example.SoloistAmplifier",
    path: "/path/to/SoloistAmplifier.vst3",
    type: 3,
    AmplifierNo: 1
  },
  Eddie51Amplifier: {
    name: "Eddie 51 Amplifier",
    uid: "com.example.Eddie51Amplifier",
    path: "/path/to/Eddie51Amplifier.vst3",
    type: 3,
    AmplifierNo: 0.1
  },
  DizzlVHAmplifier: {
    name: "Dizzl VH Amplifier",
    uid: "com.example.DizzlVHAmplifier",
    path: "/path/to/DizzlVHAmplifier.vst3",
    type: 3,
    AmplifierNo: 0.5
  }
};
const createVST3ParameterBank = () => {
  const parameterMap = /* @__PURE__ */ new Map();
  return {
    addParameter: (labelName, parameterId, processorId) => {
      parameterMap.set(labelName, createVST3Parameter(labelName, parameterId, processorId));
    },
    getParameter: (labelName) => parameterMap.get(labelName),
    removeParameter: (labelName) => parameterMap.delete(labelName),
    getAllParameters: () => Array.from(parameterMap.values()),
    hasParameter: (labelName) => parameterMap.has(labelName),
    getParameterCount: () => parameterMap.size,
    updateProcessorId: (labelName, newProcessorId) => {
      const param = parameterMap.get(labelName);
      if (param) {
        param.processorId = newProcessorId;
        parameterMap.set(labelName, param);
      }
    }
  };
};
const parameterBanks = {
  SoloistAmplifier: createVST3ParameterBank(),
  Eddie51Amplifier: createVST3ParameterBank(),
  DizzlVHAmplifier: createVST3ParameterBank(),
  ParaPanel: createVST3ParameterBank()
};
import_electron.protocol.registerSchemesAsPrivileged([
  { scheme: "app", privileges: { secure: true, standard: true } }
]);
let isGrpcConnected = false;
let currentAmplifier = "Eddie51Amplifier";
let currentProcessorId = null;
let paraPanelProcessorId = 1;
const AmpNumId = 1964973890;
async function createWindow() {
  const win = new import_electron.BrowserWindow({
    width: 1920,
    height: 1080,
    resizable: false,
    // frame: false,
    // titleBarStyle: 'hidden',
    webPreferences: {
      nodeIntegration: false,
      contextIsolation: true,
      preload: import_path.default.join(__dirname, "../src/preload.js"),
      webviewTag: true,
      webSecurity: false,
      allowRunningInsecureContent: true
    }
  });
  if (isDevelopment) {
    await win.loadURL("http://localhost:5173");
  } else {
    win.loadFile(import_path.default.join(__dirname, "../dist/index.html"));
  }
  try {
    await import_grpcClient.default.connect();
  } catch (error) {
    console.error("Failed to connect to gRPC server:", error);
  }
  const hideScrollbarsCSS = "html, body { overflow: hidden; }";
  win.webContents.on("did-finish-load", () => {
    win.webContents.insertCSS(hideScrollbarsCSS);
    win.webContents.send("enable-drag-navigation");
  });
  win.webContents.on("will-navigate", (event, url) => {
    console.log("Will navigate to:", url);
    win.webContents.insertCSS(hideScrollbarsCSS);
  });
  win.webContents.on("new-window", (event, url) => {
    event.preventDefault();
    win.loadURL(url);
  });
  win.webContents.on("did-finish-load", () => {
    win.webContents.insertCSS(hideScrollbarsCSS);
    win.webContents.send("enable-drag-navigation");
  });
  import_electron.ipcMain.handle("switch-amplifier", async (event, amplifierType) => {
    if (!import_grpcClient.default.isConnected) {
      console.error("gRPC client is not connected. Cannot switch amplifier.");
      return { success: false, error: "gRPC client not connected" };
    }
    if (!amplifierConfigs[amplifierType]) {
      console.error(`Invalid amplifier type: ${amplifierType}`);
      return { success: false, error: "Invalid amplifier type" };
    }
    try {
      console.log("amplifierConfig:", amplifierConfigs[amplifierType]);
      try {
        await import_grpcClient.default.setParameterValue(2, AmpNumId, amplifierConfigs[amplifierType].AmplifierNo);
        console.log("Amplifier type sent successfully:", 2, AmpNumId, amplifierConfigs[amplifierType].AmplifierNo);
      } catch (error) {
        console.error("Error changing amplifier type:", error);
      }
      currentAmplifier = amplifierType;
      console.log(`Current amplifier: ${currentAmplifier}`);
      return { success: true, processorId: currentProcessorId };
    } catch (error) {
      console.error("Error switching amplifier:", error);
      return { success: false, error: error.message };
    }
  });
  import_electron.ipcMain.on("send-knob-value", async (event, { knob, value }) => {
    if (!import_grpcClient.default.isConnected) {
      console.error("gRPC client is not connected. Cannot send knob value.");
      return;
    }
    let targetParameterBank;
    if (parameterBanks.ParaPanel.hasParameter(knob)) {
      targetParameterBank = parameterBanks.ParaPanel;
    } else if (parameterBanks[currentAmplifier].hasParameter(knob)) {
      targetParameterBank = parameterBanks[currentAmplifier];
    } else {
      console.error("Invalid knob:", knob);
      return;
    }
    const knobPara = targetParameterBank.getParameter(knob);
    try {
      await import_grpcClient.default.setParameterValue(knobPara.processorId, knobPara.parameterId, value);
    } catch (error) {
      console.error("Error sending knob value:", error);
    }
  });
  import_electron.ipcMain.on("set-processor-bypass", async (event, { processorId, bypassState }) => {
    if (!import_grpcClient.default.isConnected) {
      console.error("gRPC client is not connected. Cannot set processor bypass state.");
      return;
    }
    try {
      await import_grpcClient.default.setProcessorBypassState(processorId, bypassState);
      console.log(`Processor ${processorId} bypass state set to ${bypassState}`);
    } catch (error) {
      console.error("Error setting processor bypass state:", error);
    }
  });
}
import_electron.app.on("window-all-closed", () => {
  if (process.platform !== "darwin") {
    import_electron.app.quit();
  }
});
import_electron.app.on("activate", () => {
  if (import_electron.BrowserWindow.getAllWindows().length === 0) createWindow();
});
import_electron.app.whenReady().then(() => {
  createWindow();
  parameterBanks.ParaPanel.addParameter("INPUT", 0, 0);
  parameterBanks.ParaPanel.addParameter("THRESHOLD", 1, 1);
  parameterBanks.ParaPanel.addParameter("TIME", 1, 6);
  parameterBanks.ParaPanel.addParameter("FEEDBACK", 4, 6);
  parameterBanks.ParaPanel.addParameter("MIX", 2, 6);
  parameterBanks.ParaPanel.addParameter("REVERB MIX", 2, 7);
  parameterBanks.ParaPanel.addParameter("OUTPUT", 0, 0);
  parameterBanks.SoloistAmplifier.addParameter("PREAMP", 1805469906, 2);
  parameterBanks.SoloistAmplifier.addParameter("BASS", 2612626, 2);
  parameterBanks.SoloistAmplifier.addParameter("MIDDLE", 2612626, 2);
  parameterBanks.SoloistAmplifier.addParameter("TREBLE", 2612626, 2);
  parameterBanks.SoloistAmplifier.addParameter("PRESENCE", 2612626, 2);
  parameterBanks.SoloistAmplifier.addParameter("MASTER", 67801841, 2);
  parameterBanks.Eddie51Amplifier.addParameter("PRE GAIN", 1805469906, 2);
  parameterBanks.Eddie51Amplifier.addParameter("LOW", 2063103, 2);
  parameterBanks.Eddie51Amplifier.addParameter("MID", 157009333, 2);
  parameterBanks.Eddie51Amplifier.addParameter("HIGH", 365752948, 2);
  parameterBanks.Eddie51Amplifier.addParameter("PRESENCE", 935461147, 2);
  parameterBanks.Eddie51Amplifier.addParameter("POSTGAIN", 67801841, 2);
  parameterBanks.DizzlVHAmplifier.addParameter("GAIN", 1805469906, 2);
  parameterBanks.DizzlVHAmplifier.addParameter("BASS", 2063103, 2);
  parameterBanks.DizzlVHAmplifier.addParameter("MIDDLE", 157009333, 2);
  parameterBanks.DizzlVHAmplifier.addParameter("TREBLE", 365752948, 2);
  parameterBanks.DizzlVHAmplifier.addParameter("PRESENCE", 935461147, 2);
  parameterBanks.DizzlVHAmplifier.addParameter("VOLUME", 67801841, 2);
});
if (isDevelopment) {
  process.on("SIGTERM", () => {
    import_electron.app.quit();
  });
}
